import 'package:encrypt/encrypt.dart';
import 'package:get_it/get_it.dart';
import 'package:mobile_app.core/injection_container.dart' as core_di;
import 'package:mobile_app.home.menu/menu_page/domain/helpers/is_account_deletion_action_reasonable/helper.dart';
import 'package:mobile_app.home.menu/menu_page/domain/helpers/is_ios_payment_by_sim_card_action_reasonable/helper.dart';
import 'package:mobile_app.home.menu/menu_page/domain/helpers/is_payment_through_website_action_reasonable/helper.dart';
import 'package:mobile_app.home.menu/menu_page/domain/helpers/is_purchase_item_page_opening_action_reasonable/helper.dart';
import 'package:mobile_app.home.menu/menu_page/domain/helpers/is_purchase_restoration_action_reasonable/helper.dart';
import 'package:mobile_app.home.menu/menu_page/domain/helpers/is_subscription_management_action_reasonable/helper.dart';
import 'package:mobile_app.home.menu/menu_page/domain/repositories/backup_repository/repository.dart';
import 'package:mobile_app.home.menu/menu_page/domain/use_cases/create_backup/use_case.dart';
import 'package:mobile_app.home.menu/menu_page/domain/use_cases/delete_user/use_case.dart';
import 'package:mobile_app.home.menu/menu_page/domain/use_cases/get_initial_data/use_case.dart';
import 'package:mobile_app.home.menu/menu_page/domain/use_cases/handle_premium_access_status_outer_update/use_case.dart';
import 'package:mobile_app.home.menu/menu_page/domain/use_cases/handle_user_outer_update/use_case.dart';
import 'package:mobile_app.home.menu/menu_page/domain/use_cases/reset_progress/use_case.dart';
import 'package:mobile_app.home.menu/menu_page/domain/use_cases/restore_backup/use_case.dart';
import 'package:mobile_app.home.menu/menu_page/domain/use_cases/sign_out/use_case.dart';
import 'package:mobile_app.home.menu/menu_page/domain/use_cases/write_to_developers_by_email/use_case.dart';
import 'package:mobile_app.home.menu/menu_page/infrastructure/repositories/backup_repository/repository.dart';

final sl = GetIt.asNewInstance();

Future<void> init() async {
  // domain helpers

  sl.registerLazySingleton<IsAccountDeletionActionReasonable>(() {
    return const IsAccountDeletionActionReasonableImpl();
  });

  sl.registerLazySingleton<IsIosPaymentBySimCardActionReasonable>(() {
    return const IsIosPaymentBySimCardActionReasonableImpl();
  });

  sl.registerLazySingleton<IsPaymentThroughWebsiteActionReasonable>(() {
    return const IsPaymentThroughWebsiteActionReasonableImpl();
  });

  sl.registerLazySingleton<IsPurchasePageOpeningActionReasonable>(() {
    return const IsPurchasePageOpeningActionReasonableImpl();
  });

  sl.registerLazySingleton<IsPurchaseRestorationActionReasonable>(() {
    return const IsPurchaseRestorationActionReasonableImpl();
  });

  sl.registerLazySingleton<IsSubscriptionManagementActionReasonable>(() {
    return const IsSubscriptionManagementActionReasonableImpl();
  });

  // use cases

  sl.registerLazySingleton<CreateBackup>(() {
    return CreateBackupImpl(
      backupRepository: sl(),
    );
  });

  sl.registerLazySingleton<DeleteUser>(() {
    return DeleteUserImpl(
      userRepository: core_di.sl(),
      analyticsService: core_di.sl(),
      handleAccessCredentialUpdate: core_di.sl(),
      userApiRepository: core_di.sl(),
      isAccountDeletionActionReasonable: sl(),
    );
  });

  sl.registerLazySingleton<GetInitialData>(() {
    return GetInitialDataImpl(
      isIosPaymentBySimCardActionReasonable: sl(),
      isPaymentThroughWebsiteActionReasonable: sl(),
      isPurchasePageOpeningActionReasonable: sl(),
      isPurchaseRestorationActionReasonable: sl(),
      isSubscriptionManagementActionReasonable: sl(),
      isAccountDeletionActionReasonable: sl(),
    );
  });

  sl.registerLazySingleton<HandlePremiumAccessStatusOuterUpdate>(() {
    return HandlePremiumAccessStatusOuterUpdateImpl(
      isIosPaymentBySimCardActionReasonable: sl(),
      isPaymentThroughWebsiteActionReasonable: sl(),
      isPurchasePageOpeningActionReasonable: sl(),
      isPurchaseRestorationActionReasonable: sl(),
      isSubscriptionManagementActionReasonable: sl(),
    );
  });

  sl.registerLazySingleton<HandleUserOuterUpdate>(() {
    return HandleUserOuterUpdateImpl(
      isAccountDeletionActionReasonable: sl(),
    );
  });

  sl.registerLazySingleton<ResetProgress>(() {
    return ResetProgressImpl(
      learningContentRepository: core_di.sl(),
      userRepository: core_di.sl(),
    );
  });

  sl.registerLazySingleton<RestoreBackup>(() {
    return RestoreBackupImpl(
      learningContentRepository: core_di.sl(),
      userRepository: core_di.sl(),
      backupRepository: sl(),
    );
  });

  sl.registerLazySingleton<SignOut>(() {
    return SignOutImpl(
      authApiRepository: core_di.sl(),
      userRepository: core_di.sl(),
      handleAccessCredentialUpdate: core_di.sl(),
      analyticsService: core_di.sl(),
      isAccountDeletionActionReasonable: sl(),
    );
  });

  sl.registerLazySingleton<WriteToDevelopersByEmail>(() {
    return WriteToDevelopersByEmailImpl(
      emailService: core_di.sl(),
      getTtsVoiceTitle: core_di.sl(),
    );
  });

  // repositories

  sl.registerLazySingleton<BackupRepository>(() {
    return BackupRepositoryImpl(
      encrypter: Encrypter(AES(Key.fromLength(32))),
      iv: IV.fromLength(16),
    );
  });
}
